package com.mysqldemo.service.serviceImpl;
import javax.annotation.Resource;
import com.mysqldemo.mappers.RecordMapper;

import com.mysqldemo.service.RecordService;

import com.mysqldemo.entity.po.Record;

import com.mysqldemo.entity.query.RecordQuery;

import com.mysqldemo.entity.vo.PaginationResultVO;

import org.springframework.stereotype.Service;

import java.util.List;

import com.mysqldemo.enums.PageSize;

import com.mysqldemo.entity.query.SimplePage;

/**
 * @Description 点赞记录Mapper
 * @Author 徐大勇
 * @Version 1.8.0_131
 * @date 2023/07/06
 */
@Service("RecordService")
public class RecordServiceImpl implements RecordService {

	@Resource
	private RecordMapper<Record,RecordQuery> RecordMapper;

	@Override
//通过RecordQuery查询
	public List<Record> selectByParam(RecordQuery query){
		return this.RecordMapper.selectList(query);
	}

	@Override
//通过条件查询数量
	public Integer selectCountByParam(RecordQuery query){
		return this.RecordMapper.selectCount(query);
	}

	@Override
//分页查询
	public PaginationResultVO<Record> findListByPage(RecordQuery query){
		Integer count = this.selectCountByParam(query);
		int pageSzie = query.getPageSize() == null? PageSize.SIZE15.getSize():query.getPageSize();
		SimplePage page = new SimplePage(query.getPageNo(),count,pageSzie);
		List<Record> list = this.selectByParam(query);
		PaginationResultVO<Record> resultVO = new PaginationResultVO<>(count,page.getPageSize(),page.getPageNo(),list);
		return  resultVO;

	}

	@Override
//插入
	public Integer add(Record bean){
		return this.RecordMapper.insert(bean);
	}

	@Override
//批量插入
	public Integer addBatch(List<Record> list){
		if(list == null || list.size() == 0){
			return 0;
		}
		return this.RecordMapper.insertBatch(list);
	}
	@Override
//批量插入或更新
	public Integer addOrUpdateBatch(List<Record> list){
		if(list == null || list.size() == 0){
			return 0;
		}
		return this.RecordMapper.updateOrInsert(list);
	}


	@Override
//通过OpType查询
	public Record getByOpType(Integer opType) {
		return this.RecordMapper.selectByOpType(opType);
	}

	@Override
//通过OpType更新
	public Integer updateByOpType(Record bean , Integer opType) {
		return this.RecordMapper.updateByOpType(bean,opType);
	}

	@Override
//通过OpType删除
	public Integer deleteByOpType(Integer opType) {
		return this.RecordMapper.deleteByOpType(opType);
	}



	@Override
//通过OpId查询
	public Record getByOpId(Integer opId) {
		return this.RecordMapper.selectByOpId(opId);
	}

	@Override
//通过OpId更新
	public Integer updateByOpId(Record bean , Integer opId) {
		return this.RecordMapper.updateByOpId(bean,opId);
	}

	@Override
//通过OpId删除
	public Integer deleteByOpId(Integer opId) {
		return this.RecordMapper.deleteByOpId(opId);
	}

}
